热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Lintidea:`Err(_)`

Thisisthe3rdscenariofoundbythispaperthatcommonlycausescriticalfailures:Er

This is the 3rd scenario found by this paper that commonly causes critical failures: "Error handlers that catch an abstract exception type (e.g. Exception or Throwable in Java) and then take drastic action such as aborting the system."

Now, I don't know if this directly translates. And I think the result_unwrap_used and option_unwrap_used lints catch the most common ways of doing this in Rust! But there's another way, and I don't know if this is common enough to justify a lint:

1
2
3
4
5
6
7
8
9
 rust

match something {

    Ok(stuff) => {

        // happy path stuff

    },

    Err(_) => {

        panic!("stop the world");

    },

}

the key parts being the matching of any type of error, and the drastic action in the

1
Err

arm.

Again, please do close this if this doesn't seem like a worthwhile idea!! <3

该提问来源于开源项目:rust-lang/rust-clippy

is there a preferring when to use which?




1
ast

tends to be simpler and more stable so usually if it's possible, go for it.

1
hir

however is more powerful, names, types, functions, modules, constants, etc. have all be resolved and we can use that information.



is there a way I can convert between the structures in two modules?

No. Note that this would rarely be useful as almost all information in

1
ast

is also available in

1
hir

.


   



推荐阅读
author-avatar
mobiledu2502855037
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有